import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import approvals from './modules/approvals'
import attendances from './modules/attendances'
import departments from './modules/departments'
import employees from './modules/employees'
import permission from './modules/permission'
import salarys from './modules/salarys'
import setting from './modules/setting'
import social from './modules/social'

//静态路由
export const constantRoutes = [{
            path: '/login',
            component: () =>
                import ('@/views/login/index'),
            hidden: true
        },

        {
            path: '/404',
            component: () =>
                import ('@/views/404'),
            hidden: true
        },

        {
            path: '/',
            component: Layout,
            redirect: '/dashboard',
            children: [{
                path: 'dashboard',
                name: 'Dashboard',
                component: () =>
                    import ('@/views/dashboard/index'),
                meta: { title: '首页', icon: 'dashboard' }
            }]
        },
        {
            path: "/import",
            component: Layout,
            hidden: true, //隐藏左侧菜单栏中
            children: [{
                path: "", //二级路由path什么都不写
                component: () =>
                    import ("@/views/import")
            }]
        },
        // 404 page must be placed at the end !!!需要放在动态路由后面
        // { path: '*', redirect: '/404', hidden: true }
    ]
    //定义一个动态路由变量
    //这里导出变量,后期权限会用到
export const asyncRouters = [
    approvals,
    attendances,
    departments,
    employees,
    permission,
    salarys,
    setting,
    social
]

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: [...constantRoutes] //静态路由和动态路由临时合并
})

const router = createRouter() //实例化一个路由

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router